<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<div class="uc-nav">
    <ul  id="content_grid">
        <li class="active"><a href="javascript:;">全部</a></li>
        <li status="1"><a href="javascript:;">已回复</a></li>
        <li status="0"><a href="javascript:;">未回复</a></li>
    </ul>
</div>
<div  >
    <div id="content_consults" class="ucr-centent">
    </div>
    <div style="text-align: center;">
        <div id="page" class="pagination"></div>
    </div>
</div>
<!-- 模板-->
<script id="temp_consults" type="text/html">
    <table class="table table-border">
        <colgroup>
            <col width="20%">
            <col width="20%">
            <col width="20%">
            <col width="20%">
            <col width="20%">
        </colgroup>
        <thead>
        <tr>
            <th>编号</th>
            <th>主题</th>
            <th>日期时间</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {{if list.length==0}}
        <tr>
            <td colspan="5">暂未找到您的数据</td>
        </tr>
        {{/if}}
        {{each list as value i}}
        <tr>
            <td>{{value.cNum}}</td>
            <td>{{value.subject}}</td>
            <td>{{value.cosTime}}</td>
            <td>
                {{ if value.consultAnswer}}
                已回复
                {{else}}
                未回复
                {{/if}}
            </td>
            <td>
                <a href="javascript:;" class="btn btn-xs btn-blue" onclick="showDetail('{{value.guid}}')">查看</a>
            </td>
        </tr>
        {{/each}}
        </tbody>
    </table>

</script>
<script id="temp_detail" type="text/html">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">
            <span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
        </button>
        <h2 class="thing-h">咨询详情</h2>
    </div>
    <div class="modal-body">
        <div class="thing-item">
            <div class="thing-item-bd">
                <form class="form-horizontal">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">咨询主题：</label>
                        <div class="col-sm-8">
                            <textarea class="form-control" rows="3" readonly="readonly">{{subject}}</textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">咨询内容：</label>
                        <div class="col-sm-8">
                            <textarea class="form-control" rows="3" readonly="readonly">{{content}}</textarea>
                        </div>
                    </div>
                    {{if consultAnswer}}
                    <div class="form-group">
                        <label class="col-sm-2 control-label">回复内容：</label>
                        <div class="col-sm-8">
                            <textarea class="form-control" rows="3" readonly="readonly">{{consultAnswer.conetent}}</textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">受理单位：</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" readonly="readonly" value="{{consultAnswer.answerDeptName}}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">处理时间：</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" readonly="readonly" value="{{consultAnswer.answerTime}}">
                        </div>
                    </div>
                    {{/if}}
                </form>
            </div>
        </div>
    </div>
    <div class="modal-footer">
        <div class="btn-box">
            <a  class="btn btn-yellow btn-lg" href="javascript:;" onclick="$('.detail-modal').modal('hide');">取消</a>
        </div>
    </div>
</script>
<div class="modal fade detail-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content"  id="content_detail">

        </div>
    </div>
</div>
<script>
    var page_index=1,page_size=10;
    $(function(){
        $(".uc-nav li").each(function(){
            $(this).click(function(){
                $(".active").removeClass("active");
                $(this).addClass("active");
                getList(page_index,page_size,$(this).attr("status"));
            })
        })
        getList(page_index,page_size);
    });
    function getList(pi,ps,status){
        var data={
            ps:ps,
            pi:pi,
            sb:'t.cos_time',
            sd:'desc',
            q_consultant_s_eq:"${current_member.guid}"
        };
        if(status==1){
            data["q_t1.guid_s_nn"]=status;
        }else if(status==0){
            data["q_t1.guid_s_n"]=status;
        }
        $.ajax({
            url:"<c:url value='/handyconsult/page'/>",
            type:"GET",
            data:data,
            dataType:"json",
            success:function(res){
                if(res.succ){
                    var shtml = template("temp_consults", res.data);
                    $("#content_consults").html(shtml);
                    $("#page").jqPaginator({
                        totalPages: res.data.totalPage==0?1:res.data.totalPage,
                        visiblePages: 10,
                        currentPage: pi,
                        pageSize: ps,
                        onPageChange: function (n,type) {
                            if(type=='change'){
                                getList(n, ps,status);
                            }
                        }
                    });
                }else{toast(res.msg);}
            },
            error:function(res){toast(res.msg);}
        });
    }
    function showDetail(id) {
        $.ajax({
            type: "GET",
            url: "<c:url value='/handyconsult/'/>"+id,
            dataType: "json",
            success: function (resp) {
                if(resp.succ){
                    var shtml = template("temp_detail", resp.data);
                    $("#content_detail").html(shtml);
                    $('.detail-modal').modal();
                }else{
                    toast(resp.msg);
                }
            },
            error: function () {
                toast("服务器异常");
            }
        });

    }
</script>